package com.hxx.day9;

import org.junit.Test;

public class TestDemo1 {
    @Test
    public void testCThread() {
        //lambda表达式实现Runnable接口
        Runnable runnable = ()-> System.out.println("C线程运行");
        Thread t = new Thread(runnable);
        t.start();// 启动C线程
    }

    public static void main(String[] args) {
        C c = new C();
        Thread t = new Thread(c);
        t.start();// 启动C线程
        //异步调用
        show();
    }

    public static void show(){
        System.out.println("show方法运行");
    }

    /**
     * 线程优先级
     */
    @Test
    public void testPriority(){
        //创建线程
        Runnable runnable = ()-> {
            for (int index = 0; index < 10; index++) {
                System.out.println(Thread.currentThread().getName()+"------>>"+index);
            }
        };
        Thread t = new Thread(runnable,"first");
        //设置线程优先级
        t.setPriority(Thread.MAX_PRIORITY);
        t.start();// 启动线程

        Thread t2 = new Thread(runnable,"second");
        t2.setPriority(Thread.MIN_PRIORITY);
        t2.start();// 启动线程
    }
}
class C implements Runnable{
    @Override
    public void run() {
        for (int index = 0; index < 10; index++) {
            //阻塞：休眠
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(index);
        }
    }
}



























